from enum import Enum


class StockCategoryEnum(Enum):
    # 股票分类枚举
    UNIQUE = ("unique", "大盘唯一")
    SECTOR_ETF = ("sector", "板块指数")
    INDIVIDUAL = ("individual", "个股")

    def __init__(self, key: str, description: str):
        self.key = key
        self.description = description

    def __str__(self):
        return self.key

    @classmethod
    def get_category_list(cls):
        """获取股票分类描述列表"""
        return [category.description for category in cls]

    @classmethod
    def get_default(cls):
        """获取默认分类"""
        return cls.INDIVIDUAL.description
    
    @classmethod
    def from_description(cls, description):
        """
        根据描述获取枚举成员
        :param description: 描述字符串
        :return: 对应的枚举成员或 None
        """
        for member in cls:
            if member.description == description:
                return member
        return None
